package com.codingapi.websocket.core.handler.netty;

import com.codingapi.websocket.core.util.ChannelUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author modificial
 * @date 2018/7/19
 * @company codingApi
 * @description 适配器
 */
public abstract class AbstractInboundHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        String id = ChannelUtil.getChannelCtxId(ctx);
        this.doChannelRead(id, ctx, msg);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {

        String id = ChannelUtil.getChannelCtxId(ctx);
        this.doExceptionCaught(id, ctx, cause);
    }


    public abstract void doChannelRead(String channelId, ChannelHandlerContext ctx, Object msg) throws Exception;

    public abstract void doExceptionCaught(String channelId, ChannelHandlerContext ctx, Throwable cause) throws Exception;


}
